package org.learn.file;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class ObjectOutputStream_ {
    public static void main(String[] args) throws Exception{
        //序列化后，保存的文件格式，不是存文本，而是按照他的格式来保存
        String filePath = "d:\\data.dat";

        ObjectOutputStream oos  = new ObjectOutputStream(new FileOutputStream(filePath));

        //序列化数据到地址文件中
        oos.writeInt(100);
        oos.writeBoolean(true);
        oos.writeChar('a');
        //保存一个dog对象
        oos.writeObject(new Dog("大黄",18));

        oos.close();
        System.out.println("数据保存完毕");

    }
}
class Dog implements Serializable {
    private String name ;
    private int age ;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
